﻿Imports Phila
Imports Phila.Sql
Imports Phila.CommonClasses
Imports Telerik.WebControls

Public Class ViewZones1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try

        Catch ex As Exception

        End Try
    End Sub

    Protected Sub bindGridView()
        Dim strSql As String
        strSql = "select distinct ptz.Id, ptz.Name, ptz.Thumbnail, ptz.IsActive, ptc.Id as CId, ptc.Name as CountryName "
        strSql += "from ptn_CatZoneTours ptcz LEFT JOIN ptn_Countries ptc ON ptc.id=ptcz.CountryId "
        strSql += "INNER  JOIN ptn_Zones ptz ON ptz.id=ptcz.zoneId"
        Fill_Grid(radGrid, strSql)
    End Sub

    'Private Sub gvZones_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvZones.RowEditing
    '    Dim CId As Integer = gvZones.Rows(e.NewEditIndex).Cells(0).Text
    '    Response.Redirect("EditZone.aspx?zid=" & CId)
    'End Sub

    Protected Sub radGrid_DeleteCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles radGrid.DeleteCommand
        Dim ID As String = (CType(e.Item, GridDataItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID").ToString
        Try
            Dim txt As Array
            txt = RetriveData("select SUM(TourId) from ptn_CatZoneTours where ZoneId=" & ID, 0)
            If txt(0) Is Nothing Or txt(0) = 0 Then
                Insert_Update_Delete_Record("delete from ptn_Zones where id=" & ID)
                Insert_Update_Delete_Record("delete from ptn_CatZoneTours where ZoneId=" & ID)
                radGrid.Controls.Add(New LiteralControl(("<div class='message success'>Deleted successfully.</div>")))
            Else
                radGrid.Controls.Add(New LiteralControl(("<div class='message error'>Unable to Delete Record. Reason: Some tours belonging this Zone</div>")))
                lblMsg.Visible = True
                lblMsg.Text = "Unable to Delete Record. Reason: Some tours belonging this Zone"
                lblMsg.ForeColor = Drawing.Color.Red
            End If
        Catch ex As Exception
            'radGrid.Controls.Add(New LiteralControl(("Unable to Delete Record. Reason: " + ex.Message)))
            lblMsg.Text = "Unable to Delete Record. Reason: " + ex.Message
            lblMsg.ForeColor = Drawing.Color.Red
            e.Canceled = True
        End Try

    End Sub

    Protected Sub radGrid_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles radGrid.NeedDataSource
        bindGridView()
    End Sub

End Class